using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace CPGVertragsverwaltung.Viewer
{
    public partial class PermissionsEditor : UserControl
    {
        public event DataChangedDelegate PermissionChanged;
        private Boolean mUserHasClicked = true;

        public PermissionsEditor()
        {
            InitializeComponent();
            //Controls Properties
        }

        public Boolean canRead
        {
            get
            {
                return chkRead.Checked;
            }
            set
            {
                mUserHasClicked = false;
                chkRead.Checked = value;
                Application.DoEvents();
                mUserHasClicked = true;
            }
        }

        public Boolean canWrite
        {
            get
            {
                return chkWrite.Checked;
            }
            set
            {
                mUserHasClicked = false;
                chkWrite.Checked = value;
                Application.DoEvents();
                mUserHasClicked = true;
            }

        }

        //fire Event
        private void chkRead_CheckStateChanged(object sender, EventArgs e)
        {
            if (this.PermissionChanged != null &&  mUserHasClicked == true)
            {
                this.PermissionChanged();
            }
        }

        private void chkWrite_CheckedChanged(object sender, EventArgs e)
        {
            if (this.PermissionChanged != null && mUserHasClicked == true )
            {
                this.PermissionChanged();
            }
        }
    }
}
